class CreateAttendances < ActiveRecord::Migration
  def self.up
    create_table :attendances do |t|
		t.column :user_id, :integer
		t.column :event_id, :integer
		t.column :token, :string
		t.column :attending, :string
    end
	# add database level constraints for foreign keys linking user and events tables to attendances.
	# This is DDL lingo specific to MySQL since as for R 1.7 Rails migrations doesn't support specifying 
	# foreign keys in a DB agnostic way
	execute "alter table attendances add constraint fk_attendances_users foreign key (user_id) references users(id)"
	execute "alter table attendances add constraint fk_attendances_events foreign key (event_id) references events(id)" 
  end
  
 
  
  def self.down
    drop_table :attendances
  end
end
